package com.leet.everyday;

public class LongestPalindrome {
    String ans = "";
    public String longestPalindrome(String s) {
        for(int i = 0; i < s.length(); i++){
            helper(i,i,s);
            helper(i,i+1,s);
        }
        return ans;
    }
    public void helper(int low, int high, String s){
        // 从中间往左两边，要判断两边是否越界
        while (low >= 0 && high < s.length() && s.charAt(low) == s.charAt(high)){
            low--;
            high++;
        }
        if(high - low> ans.length() + 1){
            ans = s.substring(low + 1,high);
        }
    }
}
